package com.lwlean.test.amqp;


import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration  
public class AmqpConfig {  
  
    public static final String EXCHANGE   = "cti-exchange";
//    public static final String EXCHANGE   = "cti-event-exchange";
    public static final String ROUTINGKEY = "billing";
//    public static final String ROUTINGKEY = "cti.#";

    @Bean  
    public ConnectionFactory connectionFactory() {  
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
//        connectionFactory.setAddresses("127.0.0.1:5672");
//        connectionFactory.setUsername("guest");
//        connectionFactory.setPassword("guest");
//        connectionFactory.setVirtualHost("/");
        connectionFactory.setAddresses("192.168.96.43:9102");
        connectionFactory.setUsername("tongyi");
        connectionFactory.setPassword("123123");
        connectionFactory.setVirtualHost("tongyiHost");
        connectionFactory.setPublisherConfirms(true); //必须要设置
        return connectionFactory;
    }  
    
    @Bean
    @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    //必须是prototype类型  
    public RabbitTemplate rabbitTemplate() {  
        RabbitTemplate template = new RabbitTemplate(connectionFactory());  
        return template;  
    }  
}  